home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1540 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.1 KB

  1. Path: news.lpr.carel.fi!usenet
  2. From: aril@cmt.lpr.mail.carel.fi (Ari Lukumies)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Fastest way to index thru an array????
  5. Date: Thu, 11 Jan 1996 13:47:01 GMT
  6. Organization: Carelcomp Forest Oy
  7. Message-ID: <4d34p7$kj9@tahko.lpr.carel.fi>
  8. References: <4d1g3k$o09@solaris.cc.vt.edu>
  9. NNTP-Posting-Host: renoir.cclahti.carel.fi
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Ashutosh Gokhale <ashutosh> wrote:
  13.  
  14. >Suppose I have an array A[][][] which I declare as
  15. >    double ***A and then assign memory to it using new operator.
  16. >Now consider that A has dimensions A[50][60][70]. Then I can index thru ALL
  17. >entries of A using
  18. >for(i=1; i<50; i++)
  19. > {
  20. >   for(j=1; j<60; j++)
  21. >    {
  22. >      for(k=1; k<70; k++)
  23. >       {
  24. >         A[i][j][k] = <some expression>;
  25. >       }
  26. >    }
  27. > }
  28. >But the above way is surely the most time-INEFFICIENT way.
  29. >Can someone suggest me the MOST time efficient way of indexing through A[][][]?
  30.  
  31. >Thanks a lot
  32.  
  33. Try this:
  34.  
  35.     double    *p = A;
  36.  
  37.     for (i = 0; i < 50*60*70; i++)
  38.         *p++ = <some expression>;
  39.  
  40. BTW, array indexes in C/C++ begin at 0, _not_ at 1.
  41.  
  42. Later,
  43. AriL
  44.  
  45. All my opinions are mine and mine alone.
  46.  
  47.